package com.zegome.game.oanquan;

import android.graphics.Bitmap;

import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.zegome.facebook.IFacebookBridge;
import com.zegome.facebook.IFacebookEventListener;
import com.zegome.facebook.IFacebookProcessorListener;
import com.zegome.game.MainActivity;
import com.zegome.game.main.AndroidGameController;
import com.zegome.game.main.ZegomeActivity;
import com.zegome.game.oanquan.scene.UICenter;
import com.zegome.game.oanquan.scene.menu.MenuScreen;
import com.zegome.game.oanquan.scene.play.PlayingScreen;
import com.zegome.game.screen.GameScreen;
import com.zegome.game.screen.GameScreenOption;
import com.zegome.game.screen.OrthographicCameraGame;

public class OAnQuanController extends AndroidGameController implements IFacebookBridge {

	// ===========================================================
	// Constants
	// ===========================================================

	// ===========================================================
	// Fields
	// ===========================================================
	private IFacebookEventListener mFBEventListener;

	// ===========================================================
	// Constructor
	// ===========================================================
	public OAnQuanController(final ZegomeActivity activity, final IFacebookEventListener listener) {
		super(activity);
		
		mFBEventListener = listener;
	}
	
	// ===========================================================
	// Getter & Setter
	// ===========================================================

	// ===========================================================
	// Methods for/from SuperClass/Interfaces
	// ===========================================================
	@Override
	public void dispose() {
		super.dispose();
		GameCenter.dispose();
	}

	@Override
	public GameScreenOption onCreate() {
		final OrthographicCameraGame camera = new OrthographicCameraGame(
				GameCenter.CAMERA_WIDTH, GameCenter.CAMERA_HEIGHT);
		final GameScreenOption option = new GameScreenOption(camera, 1);
		return option;
	}

	@Override
	public GameScreen onLoadScreen() {
		final PlayingScreen playingScreen = new PlayingScreen(this, GameCenter.SCREEN_PLAYING);
		final MenuScreen menuScreen = new MenuScreen(this, GameCenter.SCREEN_MENU, this);
		attachScreen(menuScreen, playingScreen);
		
		return menuScreen;
	}

	@Override
	public void onLoadResources() {
		loadAtlas();
		loadFont();
		loadSound();
	}
	
	@Override
	public void onComplete() {
		final UICenter uiCenter= new UICenter(this, mStage, mTweenManager);
		final PlayingScreen p = (PlayingScreen)getScreen(GameCenter.SCREEN_PLAYING);
		p.setUICenter(uiCenter);
		final MenuScreen m = (MenuScreen)getScreen(GameCenter.SCREEN_MENU);
		m.setUICenter(uiCenter);
		uiCenter.start();
	}

	@Override
	public MainActivity getActivity() {
		return (MainActivity)mActivity;
	}
	
	@Override
	public void onLogin(final IFacebookProcessorListener processorListener) {
		mFBEventListener.onLogin(processorListener);
	}

	@Override
	public void onSendRequest(final IFacebookProcessorListener processorListener, final String link, final String message, final String data, final boolean isFilter) {
		mFBEventListener.onSendRequest(processorListener, link, message, data, isFilter);
	}

	@Override
	public void onOpenAction(final IFacebookProcessorListener processorListener, final Bitmap image) {
		mFBEventListener.onOpenAction(processorListener, image);
	}

	@Override
	public void onNewsFeed(IFacebookProcessorListener processorListener, String link, String name, String caption, String descript, String pictureUrl) {
		mFBEventListener.onNewsFeed(processorListener, link, name, caption, descript, pictureUrl);
	}
	// ===========================================================
	// Methods
	// ===========================================================

	private void loadAtlas() {
		load(ImageAssets.ASSET_FOLDER_ATLAS + ImageAssets.ATLAS_BG_GAME, TextureAtlas.class);
		load(ImageAssets.ASSET_FOLDER_ATLAS + ImageAssets.ATLAS_BGMENU, TextureAtlas.class);
		load(ImageAssets.ASSET_FOLDER_ATLAS + ImageAssets.ATLAS_BUTTON, TextureAtlas.class);
		load(ImageAssets.ASSET_FOLDER_ATLAS + ImageAssets.ATLAS_INGAME, TextureAtlas.class);
		load(ImageAssets.ASSET_FOLDER_ATLAS + ImageAssets.ATLAS_GAME_UI, TextureAtlas.class);
		load(ImageAssets.ASSET_FOLDER_ATLAS + ImageAssets.ATLAS_POPUP, TextureAtlas.class);
		load(ImageAssets.ASSET_FOLDER_ATLAS + ImageAssets.TRANPARENCY, Texture.class);
		load(ImageAssets.ASSET_FOLDER_ATLAS + ImageAssets.ATLAS_SETTING, TextureAtlas.class);
	}
	
	private void loadSound() {
		load(SoundAsset.ASSET_MUSIC_FOLDER + SoundAsset.ASSET_MUSIC_BOARD, Music.class);
		load(SoundAsset.ASSET_MUSIC_FOLDER + SoundAsset.ASSET_MUSIC_MENU, Music.class);
		
		load(SoundAsset.ASSET_SOUND_FOLDER + SoundAsset.ASSET_SOUND_EAT_COURTING, Sound.class);
		load(SoundAsset.ASSET_SOUND_FOLDER + SoundAsset.ASSET_SOUND_LOSE, Sound.class);
		load(SoundAsset.ASSET_SOUND_FOLDER + SoundAsset.ASSET_SOUND_WIN, Sound.class);
		load(SoundAsset.ASSET_SOUND_FOLDER + SoundAsset.ASSET_SOUND_STONE, Sound.class);
		load(SoundAsset.ASSET_SOUND_FOLDER + SoundAsset.ASSET_SOUND_EAT_1, Sound.class);
		load(SoundAsset.ASSET_SOUND_FOLDER + SoundAsset.ASSET_SOUND_EAT_4, Sound.class);
		load(SoundAsset.ASSET_SOUND_FOLDER + SoundAsset.ASSET_SOUND_EAT_8, Sound.class);
		load(SoundAsset.ASSET_SOUND_FOLDER + SoundAsset.ASSET_SOUND_CLICK, Sound.class);
	}
	
	private void loadFont() {
		load(GameCenter.ASSET_FOLDER_FONT + GameCenter.ASSET_SKIN, Skin.class);
		load(GameCenter.ASSET_FOLDER_FONT + GameCenter.ASSET_FONT_BITMAP, Texture.class);
		load(GameCenter.ASSET_FOLDER_FONT + GameCenter.ASSET_FONT, BitmapFont.class);
		load(GameCenter.ASSET_FOLDER_FONT + GameCenter.ASSET_FONT_HIGH_SCORE_BITMAP, Texture.class);
		load(GameCenter.ASSET_FOLDER_FONT + GameCenter.ASSET_FONT_HIGH_SCORE, BitmapFont.class);
	}

	// ===========================================================
	// Inner and Anonymous Classes
	// ===========================================================

}
